<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: fichiers.php,v $ 
 * $Date: 2005/08/31 10:13:46 $ 
 * $Revision: 1.2 $ 
 * 
 * ********* CVS HEADER ********* 
 */
/* Retourne le nom de l'image a afficher en fonction de l'extension */
function GetIcone($ext) {
	$icone=""; 
	switch($ext) {
		
		/* Images */
		 
		case "bmp" :
			$icone = "image1.gif";
			break; 
		case "gif" :
			$icone = "image2.gif";
			break; 
		case "jpg" : 
			$icone = "image3.gif";
			break; 
		case "png" :
			$icone = "image2.gif";
			break; 
		case "tif" :
			$icone = "image1.gif";
			break; 
		
		/* Code */
		 
		case "c" :
			$icone = "c.gif";
			break; 
		case "cpp" :
			$icone = "c.gif";
			break; 
		case "inc" :
			$icone = "php.gif";
			break; 
		case "php" :
			$icone = "php.gif";
			break; 
		case "php3" :
			$icone = "php.gif";
			break; 
		case "php4" :
			$icone = "php.gif";
			break; 
		case "sql" :
			$icone = "text.gif";
			break; 
		
		/* Video */
		 
		case "mpg" :
			$icone = "movie.gif";
			break; 
		case "avi" :
			$icone = "movie.gif";
			break; 
		case "mov" :
			$icone = "movie.gif";
			break; 
		
		/* Texte / office */
		 
		case "doc" :
			$icone = "doc.gif";
			break; 
		case "pdf" :
			$icone = "pdf.gif";
			break; 
		case "ppt" :
			$icone = "layout.gif";
			break; 
		case "pps" :
			$icone = "php.gif";
			$icone = "layout.gif";
			break; 
		case "ps" :
			$icone = "ps.gif";
			break; 
		case "rtf" :
			$icone = "quill.gif";
			break; 
		case "txt" :
			$icone = "text.gif";
			break; 
		case "xls" :
			$icone = "layout.gif";
			break; 
		
		/* Compression */
		 
		case "zip" :
			$icone = "zip.gif";
			break; 
		case "ace" :
			$icone = "compressed.gif";
			break; 
		case "tar" :
			$icone = "tar.gif";
			break; 
		case "gz" :
			$icone = "tar.gif";
			break; 
		case "uu" :
			$icone = "uu.gif";
			break; 
		case "tex" :
			$icone = "tex.gif";
			break; 
		
		/* Son */
		 
		case "mp3" :
			$icone = "sound.gif";
			break; 
		case "wav" :
			$icone = "sound.gif";
			break; 
		case "au" :
			$icone = "sound.gif";
			break; 
		case "mid" :
			$icone = "sound.gif";
			break; 
		
		/* HTML */
		 
		case "js" :
			$icone = "script.gif";
			break; 
		case "css" :
			$icone = "script.gif";
			break; 
		case "cgi" :
			$icone = "script.gif";
			break; 
		case "htm" :
			$icone = "html.gif";
			break; 
		case "html" :
			$icone = "html.gif";
			break; 
		
		/* Executable */
		 
		case "com" :
			$icone = "exe.gif";
			break; 
		case "exe" :
			$icone = "exe.gif";
			break; 
		
		/* Repertoire */

		case "dir" :
			$icone = "dir.gif";
			break; 
			
		/* Defaut */
		 
		default :
			$icone = "unknown.gif";
			break; 
	} 
	return $icone; 
}

/* Retourne l'extension du fichier */
function file_ext($fichier) { 
	return substr(strrchr($fichier, '.'), 1); 
} 

/* Formatte la taille d'un fichier */
function fsize($size) {
	$a = array("o", "Ko", "Mo", "Go", "To", "Po");
	$pos = 0;
	while ($size >= 1024) {
		$size /= 1024;
		$pos++;
	}
	return round($size,2)." ".$a[$pos];
}

/* Retourne true si l'extension est une type "texte",
 * i.e. autorise a l'edition
 */
function est_texte($ext) {
	switch ($ext) {
		case "c" :
		case "cpp" :
		case "css" :
		case "htm" :
		case "html" :
		case "inc" :
		case "js" :
		case "php" :
		case "php3" :
		case "php4" :
		case "sql" :
		case "txt" :
			$L_return = true;
			break;
		default :
			$L_return = false;
	}
	return $L_return;
}

/* Retourne true si l'extension est une type "image" */
function est_image($ext) {
	switch ($ext) {
		case "bmp" :
		case "gif" :
		case "jpg" : 
		case "png" :
		case "tif" :
			$L_return = true;
			break;
		default :
			$L_return = false;
	}
	return $L_return;
}

?>